<template>
  <Form ref="formValidate" :model="ps" :label-width="120">
    <FormItem label="输入原始密码">
        <Input v-model="ps.password" type="password" placeholder="输入原始密码" style="width: 300px;"></Input>
    </FormItem>
    <FormItem label="输入新密码" >
        <Input v-model="ps.newpassword" type="password" placeholder="输入新密码" style="width: 300px;"></Input>
    </FormItem>
    <FormItem label="重复新密码" >
        <Input v-model="ps.renewpassword" type="password" placeholder="重复新密码" style="width: 300px;"></Input>
    </FormItem>

    <FormItem >
        <Button type="primary" size="large" long  @click="changePsConfirm()" style="width: 300px;">确定</Button>
    </FormItem>
  </Form>

</template>

<script>
import axios from 'axios'
export default {
  name: 'changps',
  title: '修改密码',
  data () {
    return {
      ps: {
        password: '',
        newpassword: '',
        renewpassword: '',
        idnumber: ''
      },
    }
  },
  methods: {
    changePsConfirm () {
      if (this.ps.newpassword !== this.ps.renewpassword) {
        this.$Message.error('两次密码不一致')
        return
      }
      this.ps.idnumber = this.$store.state.user.userinfo.idnumber
      axios.post('rs/logic/changepass', this.ps).then(res => {
        if (res.data.code === 200) {
          this.$Message.success('密码修改成功');
          this.ps = {
            password: '',
            newpassword: '',
            renewpassword: '',
            idnumber: ''
          }
        } else if (res.data.code === 500) {
          this.$Message.error('密码修改失败,' + res.data.msg);
        } else {
          this.$Message.error('密码修改失败');
        }

      }).catch(error => {
        this.$Message.error('密码修改失败');
      })
    },
  }
}
</script>
